﻿@model AccountViewModel
@{
    var parent = (WebViewPage)TempData["Parent"];
    var controllerName = Model.IsOrganization ? "Organizations" : "Users";

    ViewBag.NotifyPackagePushedEnabled = "Receiving package push notifications";
    ViewBag.NotifyPackagePushedNotEnabled = "Not receiving package push notifications";

    ViewBag.NotifyPackagePushedLabel = "Notify when a package is published to " + Config.Current.Brand;
    ViewBag.NotifyPackagePushedDescription = "This setting enables notifications whenever a package is published "
        + "to your account. We recommend enabling this setting so that you can inspect whether a package was "
        + "published intentionally and so that you can be notified if there are unexpected delays in publishing "
        + "your package.";

    if (Model.IsOrganization)
    {
        ViewBag.EmailAllowedEnabled = "Users can contact";
        ViewBag.EmailAllowedNotEnabled = "Users can not contact";
        ViewBag.EmailAllowedLabel = "Users can contact the organization through the "
            + Config.Current.Brand;
        ViewBag.EmailAllowedDescription = "This setting allows other registered users of the site to contact your "
            + "organization about packages that it owns using the <em>Contact Owners</em> form, or to request "
            + "that your organization become an owner of their package. Disabling this setting means users cannot "
            + "contact your organization for these reasons.";
        ViewBag.PrivacyNotice = "We will always send important account management and security notices. Also, we never "
            + "reveal the organization email address to other users.";
    }
    else
    {
        ViewBag.EmailAllowedEnabled = "Users can contact you";
        ViewBag.EmailAllowedNotEnabled = "Users can not contact you";
        ViewBag.EmailAllowedLabel = "Users can contact me through the "
            + Config.Current.Brand;
        ViewBag.EmailAllowedDescription = "This setting allows other registered users of the site to contact you about "
            + "packages that you own using the <em>Contact Owners</em> form, or to request that you become "
            + "an owner of their package. Disabling this setting means users cannot contact you for these reasons.";
        ViewBag.PrivacyNotice = "We will always send important account management and security notices. Also, we never "
            + "reveal your email address to other users.";
    }
}

@ViewHelpers.Section(parent,
         "change-notifications",
        @<text>Email Notifications</text>,
        @<text>
            @(Model.ChangeNotifications.EmailAllowed ? ViewBag.EmailAllowedEnabled : ViewBag.EmailAllowedNotEnabled) |
            @(Model.ChangeNotifications.NotifyPackagePushed ? ViewBag.NotifyPackagePushedEnabled : ViewBag.NotifyPackagePushedNotEnabled)
        </text>,
        @<text>
            @using (Html.BeginForm("ChangeEmailSubscription", controllerName, FormMethod.Post, new { aria_label = "Change email subscription settings" }))
            {
                @Html.AntiForgeryToken()

                <div>
                    <label class="brand-checkbox">
                        @Html.ShowCheckboxFor(x => x.ChangeNotifications.EmailAllowed)
                        <span><b id="emailallowed-label">@ViewBag.EmailAllowedLabel</b></span>
                    </label>
                    <div class="label-sibling">@Html.Raw(ViewBag.EmailAllowedDescription)</div>
                    @Html.ShowValidationMessagesFor(x => x.ChangeNotifications.EmailAllowed)
                </div>

                <div>
                    <label class="brand-checkbox">
                        @Html.ShowCheckboxFor(x => x.ChangeNotifications.NotifyPackagePushed)
                        <span><b id="notifypackagepushed-label">@ViewBag.NotifyPackagePushedLabel</b></span>
                    </label>
                    <div class="label-sibling">@ViewBag.NotifyPackagePushedDescription</div>
                    @Html.ShowValidationMessagesFor(x => x.ChangeNotifications.NotifyPackagePushed)
                </div>

                <p><strong>Note: </strong>@ViewBag.PrivacyNotice</p>

                <div class="row form-group">
                    <div class="col-sm-6">
                        <input type="submit" class="btn btn-brand form-control" value="Save" />
                    </div>
                    <div class="col-sm-6">
                        <button type="button" class="btn btn-brand-secondary form-control" id="cancel-change-notifications">
                            Cancel
                        </button>
                    </div>
                </div>
            }
        </text>,
        disabled: !Model.CanManage)